package cn.dakaqi.entities.user;

import cn.dakaqi.entities.IdEntity;
import cn.dakaqi.utils.qrcode.ImageType;
import cn.dakaqi.utils.qrcode.QRCode;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.Date;

/**
 * @author chunyang on 2016/4/13.
 */

@Entity
@Table(name = "U_VOLUNTEER")
public class Volunteer extends IdEntity implements Serializable
{
    private static final long serialVersionUID = -8533623225694901221L;
    private String volunteerCode;//志愿者一号通编号
    private String memberCode;//会员本地唯一编号
    private String mobile;//手机号
    private String nickName;//昵称
    private String realName;//真实姓名
    private String headUrl;//头图
    private String province;//省市
    private String city;//城市
    private String district;//区县
    private String cardType;//证件类型
    private String cardNO;//证件号
    private String residenceAddress;//现居住地
    private String job;//工作
    private String serviceField;//服务领域
    private String skill;//服务技能
    private String QQ;//QQ号
    private String sign;//个人签名
    private String weChat;//微信号
    private long times = 0L;//活动时间
    private long vTimes = 0L;//公益时间
    private int locked = 0;//是否被锁定
    private String sex = "男";//性别
    private String birthDay;//生日
    private String education;//文化成度
    private Date crateTime;//创建时间
    private int rank = 0;   //排名
    private String nation;//民族
    private String nativePlace;//籍贯
    private String type; //用户类型
    private int acts;          //个人累计活动数
    private String lastJoinActDate;//最后一次参加活动的时间
    private String client;
    private int isFinished = 0;//0未完善 1已完善
    private long userId;//用户编号

    public Volunteer(){
    }

    public long getvTimes()
    {
        return vTimes;
    }

    public void setvTimes(long vTimes)
    {
        this.vTimes = vTimes;
    }

    public Volunteer(Long id)
    {
        this.id = id;
    }

    public int getIsFinished()
    {
        return isFinished;
    }

    public void setIsFinished(int isFinished)
    {
        this.isFinished = isFinished;
    }

    public String getClient()
    {
        return client;
    }

    public void setClient(String client)
    {
        this.client = client;
    }

    public int getActs()
    {
        return acts;
    }

    public void setActs(int acts)
    {
        this.acts = acts;
    }

    public String getLastJoinActDate()
    {
        return lastJoinActDate;
    }

    public void setLastJoinActDate(String lastJoinActDate)
    {
        this.lastJoinActDate = lastJoinActDate;
    }

    public String getVolunteerCode()
    {
        return volunteerCode;
    }

    public void setVolunteerCode(String volunteerCode)
    {
        this.volunteerCode = volunteerCode;
    }

    public String getMemberCode()
    {
        return memberCode;
    }

    public void setMemberCode(String memberCode)
    {
        this.memberCode = memberCode;
    }

    public String getMobile()
    {
        return mobile;
    }

    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }

    public String getNickName()
    {
        return nickName;
    }

    public void setNickName(String nickName)
    {
        this.nickName = nickName;
    }

    public String getRealName()
    {
        return realName;
    }

    public void setRealName(String realName)
    {
        this.realName = realName;
    }

    public String getHeadUrl()
    {
        return headUrl;
    }

    public void setHeadUrl(String headUrl)
    {
        this.headUrl = headUrl;
    }
    @JsonIgnore
    public String getProvince()
    {
        return province;
    }

    public void setProvince(String province)
    {
        this.province = province;
    }
    @JsonIgnore
    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }
    @JsonIgnore
    public String getDistrict()
    {
        return district;
    }

    public void setDistrict(String district)
    {
        this.district = district;
    }

    public String getCardType()
    {
        return cardType;
    }

    public void setCardType(String cardType)
    {
        this.cardType = cardType;
    }

    public String getCardNO()
    {
        return cardNO;
    }

    public void setCardNO(String cardNO)
    {
        this.cardNO = cardNO;
    }

    public String getResidenceAddress()
    {
        return residenceAddress;
    }

    public void setResidenceAddress(String residenceAddress)
    {
        this.residenceAddress = residenceAddress;
    }

    public String getJob()
    {
        return job;
    }

    public void setJob(String job)
    {
        this.job = job;
    }

    public String getServiceField()
    {
        return serviceField;
    }

    public void setServiceField(String serviceField)
    {
        this.serviceField = serviceField;
    }

    public String getSkill()
    {
        return skill;
    }

    public void setSkill(String skill)
    {
        this.skill = skill;
    }

    public String getQQ()
    {
        return QQ;
    }

    public void setQQ(String QQ)
    {
        this.QQ = QQ;
    }

    public String getSign()
    {
        return sign;
    }

    public void setSign(String sign)
    {
        this.sign = sign;
    }

    public String getWeChat()
    {
        return weChat;
    }

    public void setWeChat(String weChat)
    {
        this.weChat = weChat;
    }

    public long getTimes()
    {
        return times;
    }

    public void setTimes(long times)
    {
        this.times = times;
    }

    public int getLocked()
    {
        return locked;
    }

    public void setLocked(int locked)
    {
        this.locked = locked;
    }
    @JsonIgnore
    public String getSex()
    {
        return sex;
    }

    public void setSex(String sex)
    {
        this.sex = sex;
    }
    @JsonIgnore
    public String getBirthDay()
    {
        return birthDay;
    }

    public void setBirthDay(String birthDay)
    {
        this.birthDay = birthDay;
    }
    @JsonIgnore
    public String getEducation()
    {
        return education;
    }

    public void setEducation(String education)
    {
        this.education = education;
    }

    // 设定JSON序列化时的日期格式
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCrateTime()
    {
        return crateTime;
    }

    public void setCrateTime(Date crateTime)
    {
        this.crateTime = crateTime;
    }
    @JsonIgnore
    public int getRank()
    {
        return rank;
    }

    public void setRank(int rank)
    {
        this.rank = rank;
    }
    @JsonIgnore
    public String getNation()
    {
        return nation;
    }

    public void setNation(String nation)
    {
        this.nation = nation;
    }
    @JsonIgnore
    public String getNativePlace()
    {
        return nativePlace;
    }

    public void setNativePlace(String nativePlace)
    {
        this.nativePlace = nativePlace;
    }
    @JsonIgnore
    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }
    public long getUserId()
    {
        return userId;
    }

    public void setUserId(long userId)
    {
        this.userId = userId;
    }

//    @Override
//    public String toString() {
//        return ToStringBuilder.reflectionToString(this);
//    }

    public static String getQr(String volunteerCode)
    {
        String qr = "";
        if(StringUtils.isNotBlank(volunteerCode))
        {
            ByteArrayOutputStream out = QRCode.from(volunteerCode).to(ImageType.PNG).stream();
            byte[] data = out.toByteArray();
            qr = new String(Base64.encodeBase64(data));
            //System.out.println(qr);
        }
        return qr;
    }

    /**
     * 检查当前用户是否完善了个人资料
     * @return
     */
    public static boolean checkInfo(Volunteer volunteer)
    {
        if(null == volunteer)
            return false;

        return volunteer.getIsFinished()==0?false:true;
//        if(StringUtils.isBlank(volunteer.getCardNO()) || StringUtils.isBlank(volunteer.getMobile()) || StringUtils.isBlank(volunteer.getBirthDay()))
//            return false;
//        return true;
    }
}
